<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> 
<head>
<%@ include file="../../include/easyui.jsp" %>
<%@ include file="../../include/pGrid.jsp" %>
<script src="/plug-in/jquery-easyui-1.5.1/plugins/jquery.choosebox.js"></script>
<title>用户管理</title>
<script>
	$(function(){
		var gridParam = {
			autoRowHeight:false,
			columns : [[
			     { field : "account", width : 120, title : "用户账号" }, 
			     { field : "nickName", width : 120, title : "姓名" }, 
			     { field : "gender", width : 80, title : "性别" },
			     { field : "mobile", width : 100, title : "手机" }, 
			     { field : "age", width : 80, title : "年龄" }, 
			     { field : "roleNames", width : 120, title : "用户角色" }, 
			     { field : "orgNoName", width : 120, title : "组织机构" }, 
			     { field : "duty", width : 100, title : "职务" }, 
			     { field : "deptName", width : 200, title : "项目部" },
			     { field : "remark", width : 250, title : "备注" ,formatter: function(value,row,index){
			    	 	value = value || '';
			     		return '<font title="'+ value +'">'+ value+'</font>'
			     }},
			     { field : "email", width : 160, title : "邮箱" },
			     { field : "status", width : 70, title : "用户状态",formatter:function (value) {
						 if(value == 0){
						     return "<b style='color: green'>正常</b>";
						 }else{
                             return "<b style='color: red'>禁用</b>";
						 }
                     } }
			]]
		};
		p.dataGrid = $(p.dataGrid).datagrid( $.extend({}, p.dataGridParam,gridParam));

		/*事件响应*/
		$("#toolbar .easyui-linkbutton").on("click", function() {
			var motion_code = $(this).attr("motion_code");p.btnOneClick($(this));
			switch (motion_code) {
				case "01":
					p.gridAdd({ title : "用户新增", width : 650, height : 400 });
					break;
				case "02":
					p.gridModify({title : "用户编辑" ,width : 650, height : 400 });
					break;
				case "03":
					var row = p.getSelection('请选择一条记录进行授权！') ;
					if(row && row.account=='sysAdm'){
						p.tip({msg: '系统账号不允许删除'}); return false;
					}
					p.gridDelete({ msg:"您确认删除当前选中用户记录？" });
					break;
				case "04":
					p.gridView({title : "用户查看", width : 650, height : 400 });		
					break;
				case "05":
					p.gridQuery();
					break;
				case "07":
					p.down({filename:'用户管理'});
					break;
				case "08":
					var row = p.getSelection('请选择一条记录进行授权！') ;
					if(row){
						var _p = {
							title : row.nickName+ "---用户角色授权", width : 500, height :550, href : p.gridConfigUrl || '',data : row ,
							buttons : [ p.buttons.submit, p.buttons.close ]
						};
						p.dialog = $("<div/>").dialog("openWin", _p);
					}
					break;
				case "11":
					var row = p.getSelection() ;
					if(row){
						$.messager.confirm('确认','您确定重置该账号的密码吗?（重置后的密码为当前账号）',function(r){    
						    if (r){    
						    	$.getJSON('/console/user/rewrite/resetPwd', row, function(result){
									if(result.flag){
										p.tip({msg: '密码重置成功！'});
										p.gridQuery();
									}else{
										p.tip({msg: '密码重置失败：'+result.msg});
									}
								});
						    }    
						});  
					}
					break;
				case "21":
                    var rows = p.dataGrid.datagrid('getSelections'), len = rows.length || 0 ;
                    if(len!=1){
                        p.tip({ msg : '请选择一条记录进行禁用！' });
                        break;
                    }
                    updateStatus("禁用","1");//禁用或者恢复的方法
                    break;
				case "22":
                    var rows = p.dataGrid.datagrid('getSelections'), len = rows.length || 0 ;
                    if(len!=1){
                        p.tip({ msg : '请选择一条记录进行恢复！' });
                        break;
                    }
                    updateStatus("恢复","0");
                    break;
				default:
					break;
				}
		});

        function updateStatus(text,status){
            var rows = p.dataGrid.datagrid('getSelections') || [];
            var len = rows.length || 0 ;
            var url = "/console/user/rewrite/updateUserStatus" || null;//访问默认的修改地址
            if(len<=0){
                p.tip({ msg : "请选择一条记录进行"+text+"!" }); return;
            }
            $.messager.confirm("温馨提示", "您确定"+text+"该客户吗?", function(r){
                if (r){
                    var data = {};
                    if(len==1){
                        data = {id: rows[0]["id"],status: status};//修改客户状态
                    }else{ data = {rows: JSON.stringify(rows)}; }
                    $.getJSON(url, data, function(result){
                        //清除选中
                        p.dataGrid.datagrid('clearSelections');
                        if(result.flag){
                            p.gridQuery();
                            p.tip({msg: text+"成功!"});
                        }
                    });
                }
            });
        }
	});
</script>
</head>
<body class="easyui-layout">
	<!-- 但行高度33px，多行时 33乘以行数  -->
	<div data-options="region:'north',split:false,border:false" style="height:33px;">
		<div class="easyui-panel" data-options="fit:true,border:false">
			<!-- 查询条件表单，根据配置进行替换  -->
			<form id="queryForm" >
			 <input type="hidden" name="className" value="${className}" />
			 <div style="margin-top:5px;margin-left:10px;float:left;">
			  <input class="easyui-textbox" name="account" style="width:240px;" data-options="label:'用户账号:',required:false" />
			<input type="hidden" name="account_searchType" value="like" />
			 </div>
			 <div style="margin-top:5px;margin-left:10px;float:left;">
			  <input class="easyui-textbox" name="mobile" style="width:240px;" data-options="label:'手机:',required:false" />
			<input type="hidden" name="mobile_searchType" value="like" />
			 </div>
			 <div style="margin-top:5px;margin-left:10px;float:left;">
			  <input class="easyui-textbox" name="nickName" style="width:240px;" data-options="label:'姓名:',required:false" />
			<input type="hidden" name="nickName_searchType" value="like" />
			 </div>
			</form>
		</div>
	</div>  

	<!-- 工具栏按钮 -->
	<div id="toolbar" class="easyui-panel" style="padding:3px;">
		<!-- 
		<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" id="b_1">新增</a>
      	<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" id="b_2">编辑</a>
     	<a href="#" class="easyui-linkbutton" iconCls="icon-cut" plain="true" id="b_3">删除</a>
     	<a href="#" class="easyui-linkbutton" iconCls="icon-rosette" plain="true" id="b_6">授权</a>
     	<a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" id="b_4">查看</a>
      	<a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" id="b_5">查询</a>
		 -->
	</div>
	
	<!-- 表格 -->
	<div region="center" border="false">
		<table id="dataGrid"></table>
	</div>
</body>
</html>